home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / MISC / BM192A.ZIP / LIGHTING.S < prev    next >
Encoding:
Text File  |  1996-02-23  |  4.4 KB  |  183 lines

  1. *=======================================================*
  2. *    Lighting module: latest update 23/02/96        *
  3. *=======================================================*
  4. *    Covers palette, colour & lighting processes    *
  5. *=======================================================*
  6. *    The contents of this module are temporary,    *
  7. *    and should not be taken seriously. I just     *
  8. *    wanted to see what lighting would look like!    *
  9. *=======================================================*
  10.  
  11. *-------------------------------------------------------*
  12. *    Dodgey hacks to set up sector lighting        *
  13. *-------------------------------------------------------*
  14.     txtlong
  15. *-------------------------------------------------------*
  16. set_lighting:
  17.     move.w        frame,framelock
  18.     rts
  19.  
  20. *-------------------------------------------------------*
  21.     txtlong
  22. *-------------------------------------------------------*
  23. process_lighting:
  24. *-------------------------------------------------------*
  25.     pushall
  26.     move.l        this_sector,a0
  27.     move.w        sector_special(a0),d2
  28.     move.w        sector_light(a0),d1
  29.     cmp.w        #1,d2
  30.     beq.s        .off
  31.     cmp.w        #2,d2
  32.     beq        .rand
  33.     cmp.w        #3,d2
  34.     beq        .rand
  35.     cmp.w        #4,d2
  36.     beq.s        .rand
  37.     cmp.w        #8,d2
  38.     beq        .osc
  39.     cmp.w        #12,d2
  40.     beq.s        .sync
  41.     cmp.w        #13,d2
  42.     beq.s        .sync
  43.     cmp.w        #17,d2
  44.     beq.s        .rand
  45. .end:    tst.w        d1
  46.     bpl.s        .p1
  47.     moveq        #0,d1
  48. .p1:    cmp.w        #255,d1
  49.     bmi.s        .ok
  50.     move.w        #255,d1
  51. .ok:    move.w        d1,sector_tag(a0)
  52.  
  53.     move.w        d1,brightness
  54.     dspwrite.b    #setluminance_command
  55.     dspwrite.w    d1
  56.     popall
  57.     rts
  58.  
  59. .sync:
  60. .off:
  61.     move.w        framelock,d2
  62.     lsr.w        #4,d2
  63.     and.w        #8-1,d2
  64.     bne.s        .end
  65.     sub.w        #100,d1
  66.     bra        .end
  67.  
  68. .rand:    move.w        framelock,d0
  69.     and.w        #3,d0
  70.     bne.s        .off
  71. .osc:    move.w        d1,d0
  72.     lsr.w        #2,d0
  73.     sub.w        d0,d1
  74.     lea        sine,a1
  75.     move.w        framelock,d0
  76.     lsl.w        #6,d0
  77.     and.w        #sinres-1,d0
  78.     move.w        (a1,d0.w*2),d0
  79.     asr.w        #8,d0
  80.     add.w        d0,d1
  81.     bra        .end
  82.  
  83. *-------------------------------------------------------*
  84. *    Load palette from WAD and generate coltables    *
  85. *-------------------------------------------------------*
  86. init_colours:
  87. *-------------------------------------------------------*
  88.     lea        ascii_playpal,a0
  89.     bsr        load_resource
  90.     tst.l        d0
  91.     beq        err_missing
  92.     move.l        a6,playpal_ptr
  93.     lea        ascii_colormap,a0
  94.     bsr        load_resource
  95.     tst.l        d0
  96.     beq        err_missing
  97.     move.l        a6,colormap_ptr
  98.     move.w        #255,redfilter
  99.     move.w        #255,greenfilter
  100.     move.w        #255,bluefilter
  101.     lea        colourtables,a2
  102.     bsr        create_palettes
  103.     rts
  104.  
  105. *-------------------------------------------------------*
  106. *    Generate 64 light levels of palette data    *
  107. *-------------------------------------------------------*
  108. create_palettes:
  109. *-------------------------------------------------------*
  110.     move.w        max_saturation,d0
  111.     sub.w        saturation,d0
  112.     add.l        #512*64,a2
  113.     move.w        #256,d5
  114.     moveq        #64-1,d7
  115. .loop:    move.w        #256-1,d6
  116.     move.l        playpal_ptr,a1
  117.     lea        -512(a2),a2
  118.     move.l        a2,a3
  119. .cols:    moveq        #0,d1
  120.     move.b        (a1)+,d1
  121.     moveq        #0,d2
  122.     move.b        (a1)+,d2
  123.     moveq        #0,d3
  124.     move.b        (a1)+,d3
  125.     mulu.w        redfilter,d1
  126.     mulu.w        greenfilter,d2
  127.     mulu.w        bluefilter,d3
  128.     lsr.l        #8,d1
  129.     lsr.l        #8,d2
  130.     lsr.l        #8,d3
  131.     mulu.w        saturation,d1
  132.     mulu.w        saturation,d2
  133.     mulu.w        saturation,d3
  134.     move.w        d0,d4
  135.     mulu.w        #base_red,d4
  136.     add.w        d4,d1
  137.     mulu.w        d5,d1
  138.     divu.w        max_saturation,d1        
  139.     move.w        d0,d4
  140.     mulu.w        #base_green,d4
  141.     add.w        d4,d2
  142.     mulu.w        d5,d2
  143.     divu.w        max_saturation,d2
  144.     move.w        d0,d4
  145.     mulu.w        #base_blue,d4
  146.     add.w        d4,d3
  147.     mulu.w        d5,d3
  148.     divu.w        max_saturation,d3
  149.     add.w        #127,d1
  150.     add.w        #127,d2
  151.     add.w        #127,d3
  152.     bfins        d1,d4{16:16}
  153.     bfins        d2,d4{21:16}
  154.     bfins        d3,d4{27:16}
  155.     move.w        d4,(a3)+
  156.     dbra        d6,.cols
  157.     subq.w        #(256/64),d5
  158.     dbra        d7,.loop
  159.     rts
  160.  
  161. *-------------------------------------------------------*
  162.             datlong
  163. *-------------------------------------------------------*
  164.  
  165. max_saturation:        dc.w    256            ; maximum saturation range
  166. saturation:        dc.w    248            ; actual colour saturation level
  167.  
  168. *-------------------------------------------------------*
  169.             bsslong
  170. *-------------------------------------------------------*
  171.  
  172. redfilter:        ds.w    1            ; red filter 0-255
  173. greenfilter:        ds.w    1            ; green filter 0-255
  174. bluefilter:        ds.w    1            ; blue filter 0-255
  175.  
  176. frame:            ds.w    1            ; some timing variables
  177. framelock:        ds.w    1            ; for hacked lighting effects
  178. brightness:        ds.w    1
  179.  
  180. *-------------------------------------------------------*
  181.             txtlong
  182. *-------------------------------------------------------*
  183.